package cn.xie.blog.serverutil.util;

import cn.hutool.core.util.StrUtil;
import cn.xie.blog.serverutil.constant.common.VerifyCodeConstant;
import lombok.experimental.UtilityClass;

import java.util.Random;

/**
 * @author: xiaoxie
 * create: 2025-04-22 18:52
 * @BelongsProject: blog-parent
 * @BelongsPackage: cn.xie.blog.serverutil.util
 * description: 验证码工具类
 */
@UtilityClass
public class VerifyCodeUtil {

    /**
     * @description:
     * @author: xiaoxie
     * @date: 2025/4/22 下午6:53
     * @param: []
     * @return: java.lang.String
     **/
    public static String registeredCode(){
        String chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
        Random random = new Random();
        StringBuilder code = new StringBuilder();
        for (int i = 0; i < VerifyCodeConstant.CODE_LEN; i++) {
            code.append(chars.charAt(random.nextInt(chars.length())));
        }
        return code.toString();
    }
    /**
     * @description: 验证是否code是否正确
     * @author: xiaoxie
     * @date: 2025/4/22 下午7:01
     * @param: [code]
     * @return: java.lang.String
     **/
    public static Boolean verifyRegisteredCode(String code,String registeredCode){
        if(StrUtil.isBlank(code)) {
            return Boolean.FALSE;
        }
        return StrUtil.equalsIgnoreCase(code, registeredCode);
    }
}
